package com.beiding.my.common;

import java.util.HashMap;
import java.util.Map;

public class QuoteContext {
    Map<Class<? extends Bo>, QuoteFlag> willDetach = new HashMap<>();
    Map<Class<? extends Bo>, QuoteFlag> wllAttach = new HashMap<>();

    public void addDetach(Bo bo, String field) {
        willDetach.computeIfAbsent(bo.getClass(), k -> {
            QuoteFlag quoteFlag = new QuoteFlag();
            quoteFlag.setBo(bo);
            quoteFlag.setField(field);
            return quoteFlag;
        });
    }

    public void addAttach(Bo bo, String field) {
        wllAttach.computeIfAbsent(bo.getClass(), k -> {
            QuoteFlag quoteFlag = new QuoteFlag();
            quoteFlag.setBo(bo);
            quoteFlag.setField(field);
            return quoteFlag;
        });
    }

    public void check(Bo n, Bo o) {
        if (n == null) {
         // addDetach();
        } else {

          /*  //新增关联必须具有id
            if (q.getId() == null) {
                throw new RuntimeException("无法关联不存在的实体");
            }

            //如果当前实体尚未关联就直接添加关联
            if (_quote_b == null) {
                _wllAttach.put(q.getClass(), q);
            } else {

                //如果已经存在关联就判断本地是否已经关联了该相同id的实体
                if (!_quote_b.getId().equals(q.getId())) {
                    _wllAttach.put(q.getClass(), q);
                    _willDetach.put(_quote_b.getClass(), _quote_b);
                }
            }*/
        }

    }


}
